﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using KetBanBonPhuong;
using Telerik.Web.UI;
using System.Data.SqlClient;

public partial class Admin_UserControls_AlbumDetail : System.Web.UI.UserControl
{
    protected string path;

    protected void Page_Load(object sender, EventArgs e)
    {
        if (Request.QueryString["AlbumID"] != null)
        {
            int AlbumID = Convert.ToInt32(Request.QueryString["AlbumID"].ToString());
            Album album = Album.GetInfo(AlbumID);
            album_idLabel.Text = album.AlbumID.ToString();
            user_idLabel.Text = User.GetInfo(album.UserID).Email;
            album_nameLabel.Text = album.AlbumName;
            pathLabel.Text = album.Path;
            path = "../../Files/Album/";
            path = album.Path;
            descriptionLabel.Text = album.AlbumDescription;
            created_dateRadDatePicker.SelectedDate = album.CreateAlbumDate;
            modified_dateRadDatePicker.SelectedDate = album.LastModifyDate;
            if (album.IsShown)
            {
                is_shownCheckBox.Checked = true;
            }
            else
            {
                is_shownCheckBox.Checked = false;
            }
        }
    }

    //private string[] GetRotatorDataSource()
    //{
    //    string[] clients = { "ANATR", "ANTON", "BOTTM", "CACTU", "CENTC", "ERNSH", "LAUGB", "MAISD", "MEREP", "OCEAN" };
    //    return clients;
    //}

    protected void RadRotator1_PreRender(object sender, EventArgs e)
    {
        if (Request.QueryString["AlbumID"] != null)
        {
            int AlbumID = Convert.ToInt32(Request.QueryString["AlbumID"].ToString());
            RadRotator1.DataSource = Photo.GetByAlbum(AlbumID);
            RadRotator1.DataBind();
        }
    }
    protected void RadRotator1_ItemDataBound(object sender, Telerik.Web.UI.RadRotatorEventArgs e)
    {
        HyperLink HyperLink1 = (HyperLink)e.Item.FindControl("HyperLink1");
        Image Image1 = (Image)e.Item.FindControl("Image1");
        DataRowView row = (DataRowView)e.Item.DataItem;
        Image1.ImageUrl = "../../Files/Album/" + path + "/" + row["name"].ToString();
        HyperLink1.NavigateUrl = "../PhotoDetail.aspx?PhotoID=" + row["photo_id"];
    }
    protected void Button_delete_Click(object sender, EventArgs e)
    {
        if (Request.QueryString["AlbumID"] != null)
        {
            int AlbumID = Convert.ToInt32(Request.QueryString["AlbumID"].ToString());
            try
            {
                Album.Delete(AlbumID);
            }
            catch (SqlException)
            {
                return;
            }
            // xoa xong redirect ve trang quan ly album
        }
    }
}
